package j2024.j202410;

import java.util.*;

public class j1016 {
    /**
     * 21. 合并两个有序链表
     * 将两个升序链表合并为一个新的 升序 链表并返回。
     * 新链表是通过拼接给定的两个链表的所有节点组成的。
     *
     *
     * @param list1
     * @param list2
     * @return
     */
    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        if(list1==null){
            return list2;
        }
        if(list2==null){
            return list1;
        }
        if(list1.val<list2.val){
            list1.next = mergeTwoLists(list1.next,list2);
            return list1;
        }else {
            list2.next = mergeTwoLists(list2.next,list1);
            return list2;
        }
    }

    /**
     * 155. 最小栈
     * 设计一个支持 push ，pop ，top 操作，并能在常数时间内检索到最小元素的栈。
     *
     * 实现 MinStack 类:
     *
     * MinStack() 初始化堆栈对象。
     * void push(int val) 将元素val推入堆栈。
     * void pop() 删除堆栈顶部的元素。
     * int top() 获取堆栈顶部的元素。
     * int getMin() 获取堆栈中的最小元素。
     */
    Stack<Integer> stack ;
    Stack<Integer> minstack ;
    public void MinStack() {
        stack = new Stack<>();
        minstack = new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if(minstack.empty()){
            minstack.push(val);

        }else {
            Integer peekval = minstack.peek();
            if(val <= peekval){
                minstack.push(val);
            }
        }
    }

    public void pop() {
        if(stack.empty()){
            return;
        }
        int popval = stack.pop();
        if(popval == minstack.peek()){
            minstack.pop();
        }
    }

    public int top() {
        if(stack.empty()){
            return -1;
        }
        return stack.peek();
    }

    public int getMin() {
        if(minstack.empty()){
            return -1;
        }
        return minstack.peek();
    }
}
class niuke{
    //跳台阶扩展问题
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] dp = new int[n+1];
        dp[1] = 1;dp[2] = 2;
        for (int i = 3; i <= n; i++) {
            if(i%2==1){
                dp[n] = dp[i-1]+dp[i-2]+1;
            }else {
                dp[n] = dp[i-1]+dp[i-2];
            }
        }
        System.out.println(dp[n]);
    }
    //包含不超过两种字符的最长子串
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        int ret = 2;
        int left = 0,right = 1;
        while(right<s.length()){
            while(right<s.length() && s.charAt(left)==s.charAt(right)){
                right++;
            }
            int tmp = right;
            while(right+1<s.length() && s.charAt(right)==s.charAt(right+1)){
                right++;
            }
            if(right<s.length()){
                ret = Math.max(ret,right-left+1);
            }else {
                ret = Math.max(ret,right-left);
            }
            if(right>=s.length())ret--;
            left = tmp;
        }
        System.out.println(ret);
    }
    //字符串的排列
    boolean[] vis;
    ArrayList<String> ret;
    StringBuilder sb;
    char[] ch;
    public ArrayList<String> Permutation (String str) {
        // write code here
        ret = new ArrayList<>();
        vis = new boolean[str.length()];
        sb = new StringBuilder();
        ch = str.toCharArray();
        Arrays.sort(ch);
        dfs(0);
        return ret;
    }
    public void dfs(int cou){
        if(cou==ch.length){
            ret.add(sb.toString());
            return;
        }
        for (int i = 0; i < ch.length; i++) {
            if(i>0 &&ch[i]==ch[i] &&!vis[i])continue;
            if(!vis[i]){
                sb.append(ch[i]);
                vis[i] = true;
                dfs(cou+1);
                sb.deleteCharAt(sb.length()-1);
                vis[i] = false;
            }
        }
    }
}

